/**
 * 初始化客户退货查询详情对话框
 */
var CustomerReturnListInfoDlg = {
    id:"customerReturnListTable",
    customerReturnListInfoData : {}
};

/**
 * 清除数据
 */
CustomerReturnListInfoDlg.clearData = function() {
    this.customerReturnListInfoData = {};
}

/**
 * 设置对话框中的数据
 *
 * @param key 数据的名称
 * @param val 数据的具体值
 */
CustomerReturnListInfoDlg.set = function(key, val) {
    this.customerReturnListInfoData[key] = (typeof val == "undefined") ? $("#" + key).val() : val;
    return this;
}

/**
 * 设置对话框中的数据
 *
 * @param key 数据的名称
 * @param val 数据的具体值
 */
CustomerReturnListInfoDlg.get = function(key) {
    return $("#" + key).val();
}

/**
 * 关闭此对话框
 */
CustomerReturnListInfoDlg.close = function() {
    parent.layer.close(window.parent.CustomerReturnList.layerIndex);
}

/**
 * 收集数据
 */
CustomerReturnListInfoDlg.collectData = function() {
    this
    .set('id')
    .set('goodsCode')
    .set('goodsModel')
    .set('goodsName')
    .set('returnGoodsNumber')
    .set('returnGoodsPrice')
    .set('goodsUnit')
    .set('createBy')
    .set('createDate')
    .set('updateBy')
    .set('updateDate')
    .set('remarks')
    .set('delFlag')
    .set('customerId')
    .set('goodsId');
}

CustomerReturnListInfoDlg.initGoodsColumns = function () {
    return [
        {title: '商品ID', field: 'goodsId', visible: false, align: 'center', valign: 'middle'},
        {title: '退货数量', field: 'returnGoodsNumber', visible: true, align: 'center', valign: 'middle'},
        {title: '商品编码', field: 'goodsCode', visible: true, align: 'center', valign: 'middle'},
        {title: '商品名称', field: 'goodsName', visible: true, align: 'center', valign: 'middle'},
        {title: '商品型号', field: 'goodsModel', visible: true, align: 'center', valign: 'middle'},
        {title: '商品单位', field: 'goodsUnit', visible: true, align: 'center', valign: 'middle'},
        {title: '商品单价', field: 'returnGoodsPrice', visible: true, align: 'center', valign: 'middle'},
        {title: '退货总价', field: 'totalPrice', visible: true, align: 'center', valign: 'middle'},
        {title: '库存数量', field: 'goodsInventoryQuantity', visible: false, align: 'center', valign: 'middle'},
        {title: '库存下限', field: 'goodsMinNum', visible: false, align: 'center', valign: 'middle'},
        {title: '上次采购价格', field: 'goodsLastPurchasePrice', visible: false, align: 'center', valign: 'middle'},
        {title: '创建者', field: 'createBy', visible: false, align: 'center', valign: 'middle'},
        {title: '创建时间', field: 'createDate', visible: false, align: 'center', valign: 'middle'},
        {title: '更新者', field: 'updateBy', visible: false, align: 'center', valign: 'middle'},
        {title: '更新时间', field: 'updateDate', visible: false, align: 'center', valign: 'middle'},
        {title: '备注信息', field: 'remarks', visible: false, align: 'center', valign: 'middle'},
        {title: '删除标记（0：正常；1：删除）', field: 'delFlag', visible: false, align: 'center', valign: 'middle'},
        {title: '供应商名称', field: 'supplierId', visible: false, align: 'center', valign: 'middle'},
        {title: '商品分类id', field: 'goodsCategoryId', visible: false, align: 'center', valign: 'middle'}
    ];
}


/**
 * 提交添加
 */
CustomerReturnListInfoDlg.addSubmit = function() {

    this.clearData();
    this.collectData();

    //提交信息
    var ajax = new $ax(Feng.ctxPath + "/customerReturnList/add", function(data){
        Feng.success("添加成功!");
        window.parent.CustomerReturnList.table.refresh();
        CustomerReturnListInfoDlg.close();
    },function(data){
        Feng.error("添加失败!" + data.responseJSON.message + "!");
    });
    ajax.set(this.customerReturnListInfoData);
    ajax.start();
}

/**
 * 提交修改
 */
CustomerReturnListInfoDlg.editSubmit = function() {

    this.clearData();
    this.collectData();

    //提交信息
    var ajax = new $ax(Feng.ctxPath + "/customerReturnList/update", function(data){
        Feng.success("修改成功!");
        window.parent.CustomerReturnList.table.refresh();
        CustomerReturnListInfoDlg.close();
    },function(data){
        Feng.error("修改失败!" + data.responseJSON.message + "!");
    });
    ajax.set(this.customerReturnListInfoData);
    ajax.start();
}

$(function() {
    var defaultColumns = CustomerReturnListInfoDlg.initGoodsColumns();
    var returnCustomerId = $("#customerReturnId").val();
    var table = new BSTable(CustomerReturnListInfoDlg.id, "/customerReturnList/detail/"+ returnCustomerId, defaultColumns);
    table.setPaginationType("client");
    table.setTableHeight(0);
    table.setShowColumns(false);
    table.setShowRefresh(false);
    CustomerReturnListInfoDlg.table = table.init();
});
